#!/bin/bash
# shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
source /usr/libexec/yosemite4-common-functions

is_nuvoton_board="$(check_nuvoton_board)"

HOST_BUS=$(($1 - 1))
HOST_VIRTUAL_BUS=$(($1 + 15))
# probe server board cpld I/O expander
echo $HOST_BUS-0020 > /sys/bus/i2c/drivers/pca953x/bind
echo $HOST_BUS-0021 > /sys/bus/i2c/drivers/pca953x/bind
echo $HOST_BUS-0022 > /sys/bus/i2c/drivers/pca953x/bind
echo $HOST_BUS-0023 > /sys/bus/i2c/drivers/pca953x/bind
# probe server board I/O expander and eeprom behind i2c-mux
echo $HOST_VIRTUAL_BUS-0049 > /sys/bus/i2c/drivers/pca953x/bind
echo $HOST_VIRTUAL_BUS-0050 > /sys/bus/i2c/drivers/at24/bind
echo $HOST_VIRTUAL_BUS-0051 > /sys/bus/i2c/drivers/at24/bind
echo $HOST_VIRTUAL_BUS-0054 > /sys/bus/i2c/drivers/at24/bind

if [ -n "$is_nuvoton_board" ]
then
    # Set interface of SD BIC to I3C
    GPIOCHIP=$(basename /sys/bus/i2c/devices/$HOST_BUS-0023/*gpiochip*)
    gpioset "$GPIOCHIP" 24=1
fi
